/*****************************************************
** Author: 
** Date: 2020-06-28
*
*****************************************************/

#ifndef __HEAP_H_
#define __HEAP_H_

#ifdef __cplusplus
extern "C"{
#endif

#include <stddef.h>

#define HEAP4_BYTE_ALIGNMENT	8

#if   HEAP4_BYTE_ALIGNMENT == 16
	#define HEAP4_BYTE_ALIGNMENT_MASK ( 0x000fU )
#elif HEAP4_BYTE_ALIGNMENT == 8
	#define HEAP4_BYTE_ALIGNMENT_MASK ( 0x0007U )
#elif HEAP4_BYTE_ALIGNMENT == 4
	#define HEAP4_BYTE_ALIGNMENT_MASK	( 0x0003U )
#elif HEAP4_BYTE_ALIGNMENT == 2
	#define HEAP4_BYTE_ALIGNMENT_MASK	( 0x0001U )
#elif HEAP4_BYTE_ALIGNMENT == 1
	#define HEAP4_BYTE_ALIGNMENT_MASK	( 0x0000U )
#endif

#ifndef HEAP4_BYTE_ALIGNMENT_MASK
	#error "Invalid HEAP4_BYTE_ALIGNMENT definition"
#endif

typedef void* heap_hdl_t;

void heap4_init(heap_hdl_t heap, unsigned int size);
void heap4_blocklink_info(heap_hdl_t heap, const char *str);

void *heap4_malloc(heap_hdl_t heap, size_t xWantedSize);
void* heap4_realloc(heap_hdl_t heap, void *pv, size_t xWantedSize);
void heap4_free(heap_hdl_t heap, void *pv);

size_t heap4_freeheapsize(heap_hdl_t heap);
size_t heap4_mineverfreeheapsize(heap_hdl_t heap);

#ifdef __cplusplus
}
#endif

#endif /* __HEAP_H_ */

